package com.ftg.learn.chapter11;

import java.util.Arrays;

/**
 * 多维数组定义、
 * 语法
 *  三维 ：
 * 结构
 *
 * 例题
 *  1、10* 10 二维数组 ,并初始值 i+j
 *  2、遍历输出
 *  3、蛇型输出
 *
 * @author KangJx
 * @date 2021/7/19
 */
public class LeranManyArray {

    /**
     * 范围复制
     */
    public void testIntArr1(){
//        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
//        int[] arr1 = Arrays.copyOfRange(arr,2,5);
//        for (int t : arr1){
//            System.out.println(t);
//        }

//        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
//        int[] arr1 = new int[6];
//        System.arraycopy(arr,3,arr1,0,3);
//        for(int ab : arr1){
//            System.out.println(ab);
//        }

//        util comm
        //不重复造轮子  看别人的方法 （low -- high）

//        Arrrays 帮助类 工具类
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        System.arraycopy(arr,5,arr,2,arr.length - 5);
        for(int ab : arr){
            System.out.println(ab);
        }

        int[] a = new int[]{1,2,3};
        int[] b = a;

        boolean ist = Arrays.equals(new int[]{1,2,3},new int[]{1,2,3,4});
        System.out.println(ist);

        int[] as = new int[100];
        Arrays.fill(as,13);

        System.out.println("哈希值==>" + as.hashCode());

        //什么是hash?
        //什么是hashcode?
        //hashcode在java当中用来做什么？
        int[] t = new int[]{34,45,56,67,1,2,34,6,7};
        Arrays.sort(t);
        System.out.println(Arrays.toString(t));

    }


    public void testIntArr(){
        int[] arr = new int[]{1,2,3,4,5,6,7,8};

        int[] at = Arrays.copyOf(arr,10);
        for (int i : at){
            System.out.println(i);
        }
    }


    public void arrayHelp(){
        int[] as = new int[]{1,2,4,5,6,7,9};
        //@since 1.6
        int a = Arrays.binarySearch(as,2,6,3);
        System.out.println(a);
    }

    public void question(){
        int[][] arr = new int[10][10];

        for(int i = 0,len = arr.length;i<len;i++){
            for(int j = 0 ,jlen = arr[i] == null?0:arr[i].length;j < jlen;j++){
                arr[i][j] = i+j;
            }
        }

        System.out.println("遍历输出");
        for(int i = 0,len = arr.length;i<len;i++){
            for(int j = 0 ,jlen = arr[i] == null?0:arr[i].length;j < jlen;j++){
                System.out.print(arr[i][j]+"\t");
            }
            System.out.println();
        }
        System.out.println("蛇型输出");
        for(int i = 0,len = arr.length;i<len;i++){
            for(int j = 0 ,jlen = arr[i] == null?0:arr[i].length;j < jlen;j++){
                System.out.print(i%2 == 0 ? arr[i][j]+"\t" : arr[i][jlen - j - 1]+"\t");
            }
            System.out.println();
        }
    }


    public void testTwoArray(){
        int[][] as = new int[3][];
        as[0] = new int[]{1,2,3,4,5,6};
        as[1] = new int[]{3,4};
        as[2] = new int[]{5,6,3};
        System.out.println(as.length);
        System.out.println(as[0].length);
        System.out.println(as[1].length);
        System.out.println(as[2].length);

        int[][] as1 = new int[3][3];
        as1[0][2] = 12;

        int[][] as2;

        int[][] as3 = new int[2][];
        //null
        //A null
        //B 0
        //c nullpointerexception
        // NullPointerException : 空指针异常
        // ArrayIndexofOutBoundException
    }


}
